package com.cy.pj.modules.controller;

import com.cy.pj.common.utils.ShiroUtils;
import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.modules.entity.BaseShop;
import com.cy.pj.modules.service.IBaseShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 商城基础设置Controller
 *
 * @author kiven
 * @date 2023-02-09
 */
@Controller
@RequestMapping("/baseShop")
public class BaseShopController
{
    private String prefix = "modules/shop";

    @Autowired
    private IBaseShopService baseShopService;

    @RequiresPermissions("baseShop:view")
    @GetMapping()
    public String shop()
    {
        return prefix + "/baseShop";
    }

    /**
     * 查询商城基础设置列表
     */
    @RequiresPermissions("baseShop:list")
    @GetMapping("/list")
    @ResponseBody
    public JsonResult list(BaseShop baseShop, Integer pageCurrent)
    {
        return new JsonResult(baseShopService.selectBaseShopList(baseShop,pageCurrent));
    }

    ///**
    // * 导出商城基础设置列表
    // */
    //@RequiresPermissions("baseShop:export")
    //@PostMapping("/export")
    //@ResponseBody
    //public JsonResult export(BaseShop baseShop)
    //{
    //    List<BaseShop> list = baseShopService.selectBaseShopList(baseShop);
    //    ExcelUtil<BaseShop> util = new ExcelUtil<BaseShop>(BaseShop.class);
    //    return util.exportExcel(list, "shop");
    //}

    /**
     * 新增商城基础设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城基础设置
     */
    @RequiresPermissions("baseShop:add")
    @PostMapping("/add")
    @ResponseBody
    public JsonResult addSave(BaseShop baseShop)
    {

        baseShop.setModifyUserName(ShiroUtils.getUsername());
        baseShop.setModifyTime(new Date());
        return new JsonResult(baseShopService.insertBaseShop(baseShop));
    }

    /**
     * 修改商城基础设置
     */
    @GetMapping("/edit")
    public String edit()
    {
        return prefix + "/baseShop_edit";
    }

    @GetMapping("/id")
    @ResponseBody
    public JsonResult byId(Long  id){
        return new JsonResult(baseShopService.selectBaseShopById(id));
    }
    /**
     * 修改保存商城基础设置
     */
    @RequiresPermissions("baseShop:edit")
    @PostMapping("/edit")
    @ResponseBody
    public JsonResult editSave(BaseShop baseShop)
    {
        baseShop.setModifyTime(new Date());
        baseShop.setModifyUserName(ShiroUtils.getUser().getUsername());
        return new JsonResult(baseShopService.updateBaseShop(baseShop));
    }

    /**
     * 删除商城基础设置
     */
    @RequiresPermissions("baseShop:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public JsonResult remove(String ids)
    {
        return new JsonResult(baseShopService.deleteBaseShopByIds(ids));
    }
}
